package cn.jiahua.hospital.config;

import cn.jiahua.hospital.interceptor.ExceptionInterceptor;
import cn.jiahua.hospital.interceptor.LoginInterceptor;
import cn.jiahua.hospital.interceptor.ValidateParamInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 拦截器配置类
 */
@Configuration
class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 自定义拦截器，公共参数校验、登录权限校验
     */


    /**
     * 自定义拦截器，统一异常处理
     */
    @Resource
    ExceptionInterceptor exceptionInterceptor;

    /**
     * 自定义拦截器，参数校验
     */
    @Resource
    private ValidateParamInterceptor validateInterceptor;

    @Resource
    private LoginInterceptor loginInterceptor;


    /**
     * 添加拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(validateInterceptor).addPathPatterns("/api/**");
//        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
//                .excludePathPatterns("/page/login.html","/page/public/**","/page/home.html",
//                        "/page/doctor.html","/homePage/**","/api/**","/api/user/login/wechat");
        registry.addInterceptor(exceptionInterceptor).addPathPatterns("/**");
    }
}
